<?php
include('../../include/functions.inc.php');
$user = unserialize($_SESSION['user']);
$in = unserialize($_SESSION["invoice"]);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Pago Facturas</title>
        <link href="../../bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
        <link href="../../css/ContentStyle.css" rel="stylesheet" type="text/css" />
        <link href="../../css/tableorderer.css" rel="stylesheet" type="text/css" />
        <link href="../../js/dialog/dialog.2.0.css" rel="stylesheet" type="text/css" />
        <link href="../../js/protocalendar/datepicker.css" rel="stylesheet" type="text/css" />
        <script src="../../js/jquery.js" type="text/javascript"></script>
        <script>jQuery.noConflict();</script>
        <script src="../../bootstrap/js/bootstrap.js"></script>
        <script src="../../js/prototype.js" type="text/javascript"></script>
        <script src="../../js/jsvalidate.js" type="text/javascript"></script>
        <script src="../../js/protocalendar/prototype-date-extensions.js" type="text/javascript"></script>
        <script src="../../js/protocalendar/datepicker.js"  type="text/javascript"></script>
        <script src="../../js/dialog/dialog.2.0.js" type="text/javascript"></script>
        <script src="../../js/include.js" type="text/javascript"></script>
        <style type="text/css">
            input,
            textarea{
                width: 300px;
            }
            select{
                width: 315px;
            }
        </style>
        <script type="text/javascript">
            validations=function(){
                var error=new Array();
                var total=parseFloat($F("EFECTIVO")*1)+parseFloat($F("CHEQUE")*1)+parseFloat($F("TARJETA")*1)+parseFloat($F("DEPOSITO")*1);
                var tmp=total-parseFloat($F("TOTAL")*1);
	
                if(tmp>0){
                    error.push([$("TOTAL"), "Hay "+tmp+" excedente!"]);
                }else if(tmp<0){
                    tmp=tmp*-1;
                    error.push([$("TOTAL"), "Hay "+tmp+" faltantes!"]);
                }
	
                if(($F("DEPOSITO")*1)>0 && $F("NO_BOLETA").trim().empty()){
                    $("NO_BOLETA").value = $("NO_BOLETA").value.trim();
                    error.push([$("NO_BOLETA"), "Ingrese el numero de boleta del deposito!"]);
                }
                if($F("CHEQUE")>0 ){
                    if($F("NOCHEKE").trim().empty()){
                        $("NOCHEKE").value = $("NOCHEKE").value.trim();
                        error.push([$("NOCHEKE"), "Debe ingresar un numero de cheque!"]);
                    }
                    if($F("BANCO").empty()){
                        error.push([$("BANCO"), "Seleccione un Banco!"]);
                    }			
                    if($F("CONCEPTO").trim().empty()){
                        $("CONCEPTO").value = $("CONCEPTO").value.trim();
                        error.push([$("CONCEPTO"), "Ingrese el concepto del cheque!"]);
                    }
                }	
                if(error.size()>0){
                    return error.toArray();
                }

                return true;
            }

            showCheque=function(){
                if($F("CHEQUE")>0){
                    $('divCheque').show();
                }else{
                    $('divCheque').hide();
                }
            }
            var rsvWaysPay;
            config=function(){ 
                $("CHEQUE").observe("change",showCheque);
                $('divCheque').hide();
                rsvWaysPay=new RSV({   formID: $(document.PAGO),
                    errorFieldClass: "errorField",
                    rules: ["function,validations"],
							
                    displayType : "display-html",
                    errorHTMLItemBullet : "&#8212;",
                    onCompleteHandler:function(){
                        waitMsg("Guardando...");
                        $(document.PAGO).request({onComplete:function(r){
                                resp=r.responseJSON;
                                closeWait();
                                waitMsg("Generando impresion para factura: "+resp.FACTURA);
                                //Dialogs.alert("Generando impresion para factura: "+resp.FACTURA);
                                setTimeout(function(){fntRetardar(resp)}, 4000);
                                
                            }});
                    }
                });
            }
            function fntRetardar(resp){
                closeWait();
                $("SERIE").value=resp.SERIE;
                $("NUMERO").value=resp.NUMERO;
                $("operation").value="p";
                $(document.PAGO).submit();
            }
            addOnLoad(config);
        </script>
    </head>
    <body>
        <div id="rsvErrors"></div>
        <form id="PAGO" name="PAGO" method="GET" action="<?= $_GET['urlData'] ?>">
            <input name="operation" id="operation" type="hidden" value="pay" />
            <input type="hidden" name="SERIE" id="SERIE" />
            <input type="hidden" name="NUMERO" id="NUMERO" />
            <table class=""  width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <th scope="col" colspan="2"><ul class="nav nav-tabs"><li class="active"><a>Forma de pago</a></li></ul></th>
                </tr>
                <tr>
                    <th width="50%">&nbsp;</th>
                    <th width="50%" scope="col">
                        <div class="btn-group">
                            <input name="fin" type="button" onclick="rsvWaysPay.validate();" class="btn btn-info" id="fin" value="Finalizar" />
                            <input type="button" value="Cancelar pago" class="btn btn-info" onclick="javascript:window.history.back()" />
                        </div>
                    </th>
                </tr>
                <tr>
                    <td align="center" colspan="2">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td>MONTO A PAGAR</td>
                                <td><input type="text" readonly="readonly" value="<?php echo $in["total"]; ?>" name="TOTAL" id="TOTAL" /></td>
                            </tr>
                            <tr>
                                <td width="20%">EFECTIVO</td>
                                <td width="80%"><input name="EFECTIVO" type="text" id="EFECTIVO" value="0" /></td>
                            </tr>
                            <tr>
                                <td>TARJETA</td>
                                <td><input name="TARJETA" type="text" id="TARJETA" value="0" /></td>
                            </tr>
                            <tr>
                                <td>DEPÓSITO</td>
                                <td>
                                    <input name="DEPOSITO" type="text" id="DEPOSITO" value="0"/> 
                                    &nbsp;# BOLETA &nbsp;
                                    <input name="NO_BOLETA" style="width:200px" type="text" id="NO_BOLETA" />
                                </td>
                            </tr>
                            <tr>
                                <td>CHEQUE</td>
                                <td><input name="CHEQUE" type="text" id="CHEQUE" value="0" /></td>
                            </tr>
                        </table>
                        <br/>
                    </td>
                    <td>&nbsp;</td>
                </tr>
            </table>
            <div id="divCheque">
                <table class=""  width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <th scope="col" style="text-align: left"><legend>Datos de Cheque</legend></th>
                    </tr>
                    <tr>
                        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="20%">No. Cheque</td>
                                    <td width="80%"><input name="NOCHEKE" type="text" id="NOCHEKE" size="30" /></td>
                                </tr>
                                <tr>
                                    <td>Banco</td>
                                    <td><select name="BANCO" id="BANCO">
                                            <option value="" selected="selected">Seleccionar</option>
                                            <option value="BI" title="Banco Industrial, S.A.">Banco Industrial, S.A.</option>
                                            <option value="GYT" title="Banco G&amp;T Continental, S.A.">Banco G&amp;T Continental, S.A.</option>
                                            <option value="BAM" title="Banco Agromercantil de Guatemala, S.A.">BAM</option>
                                            <option value="REFORMADOR" title="Banco Reformador, S.A.">Banco Reformador, S.A.</option>
                                            <option value="CITY" title="Banco Citibank de Guatemala, S.A.">CITI</option>
                                            <option value="BanRural" title="Banco de Desarrollo Rural, S.A.">BANRURAL</option>
                                            <option value="Internacional" title="Banco Internacional, S.A.">INTERBANCO</option>
                                            <option value="Promerica" title="Banco Promerica, S.A.">Banco Promerica, S.A.</option>
                                            <option value="BAC" title="Banco de Am&eacute;rica Central, S.A.">BAC</option>
                                            <option value="CHN" title="El Cr&eacute;dito Hipotecario Nacional de Guatemala">CHN</option>
                                            <option value="Inmobiliario" title="Banco Inmobiliario, S.A.">Banco Inmobiliario, S.A.</option>
                                            <option value="Vivibanco" title="Primer Banco de Ahorro y Pr&eacute;stamo para la Vivienda Familiar, S.A.">VIVIBANCO</option>
                                            <option value="TRABAJADORES" title="Banco de los Trabajadores">Banco de los Trabajadores</option>
                                            <option value="FICOHSA" title="Banco Ficohsa Guatemala, S.A.">Banco Ficohsa Guatemala, S.A.</option>
                                            <option value="ANTIGUA" title="Banco de Antigua, S.A.">Banco de Antigua, S.A.</option>
                                            <option value="CREDITO" title="Banco de Cr&eacute;dito, S.A.">Banco de Cr&eacute;dito, S.A.</option>
                                            <option value="AZTECA" title="Banco Azteca de Guatemala, S.A.">Banco Azteca de Guatemala, S.A.</option>
                                            <option value="Otro">Otro</option>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td><label for="FECHACOBRO">Fecha Cobro</label></td>
                                    <td>
                                        <input name="FECHACOBRO" value="<?php echo date(FORMAT); ?>" type="text" id="FECHACOBRO" size="30" readonly="readonly" />
                                        <script type="text/javascript">
                                            new Control.DatePicker('FECHACOBRO',
                                            {icon: '../../js/protocalendar/calendar.png',dateFormat: 'yyyy-MM-dd'});
                                        </script>
                                    </td>
                                </tr>
                                <tr>
                                    <td valign="top"><label for="CONCEPTO">Concepto</label></td>
                                    <td>
                                        <label>
                                            <textarea name="CONCEPTO" id="CONCEPTO" cols="45" rows="5">N/A</textarea>
                                        </label>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </div>
        </form> 
    </body>
</html>